package com.sh.data.engine.application.service.dataquality;

import com.sh.data.engine.application.model.dto.dataquality.DataQualityChartResponse;
import com.sh.data.engine.application.model.dto.dataquality.DataQualityDistributeResponse;
import com.sh.data.engine.application.model.dto.dataquality.DataQualityViewTableResponse;
import com.sh.data.engine.common.util.ServletUtils;
import com.sh.data.engine.domain.dataquality.model.domain.DataQualityChartDomain;
import com.sh.data.engine.domain.dataquality.model.domain.DataQualityDistributeDomain;
import com.sh.data.engine.domain.dataquality.model.domain.DataQualityViewTableDomain;
import com.sh.data.engine.domain.dataquality.service.DataQualityViewService;
import com.sh.data.engine.domain.util.ConvertUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: mengzheng.mhc
 * @date: 2024/7/30 10:16
 */
@Slf4j
@Service
public class DataQualityViewApplicationService {

    @Autowired
    private DataQualityViewService dataQualityViewService;

    public List<DataQualityDistributeResponse> getDataDistribution(Integer distributeBy) {
        Long projectId = ServletUtils.getProjectId();

        List<DataQualityDistributeDomain> dataQualityDistributeDomains =
            dataQualityViewService.dataQualityDisTypeService(distributeBy, projectId);

        return ConvertUtil.copyProperties(
            dataQualityDistributeDomains, DataQualityDistributeResponse.class);
    }

    public DataQualityViewTableResponse getDataQualityTableInfo() {
        Long projectId = ServletUtils.getProjectId();
        DataQualityViewTableDomain dataQualityViewTableDomain =
            dataQualityViewService.dataQualityTableService(projectId);
        return ConvertUtil.copyProperties(dataQualityViewTableDomain, DataQualityViewTableResponse.class);
    }

    public DataQualityChartResponse getDataQualityOverview() {
        Long projectId = ServletUtils.getProjectId();
        DataQualityChartDomain dataQualityChartDomain =
            dataQualityViewService.dataQualityChartService(projectId);
        DataQualityChartResponse dataQualityChartResponse = new DataQualityChartResponse();

        dataQualityChartResponse.setDataProblemTopModelList(
            dataQualityChartDomain.getDataProblemTopModelList());

        dataQualityChartResponse.setDataQualityTodayExceptionDomains(
            dataQualityChartDomain.getDataQualityTodayExceptionDomains());
        dataQualityChartResponse.setDataTendModelList(dataQualityChartDomain.getDataTendModelList());
        return dataQualityChartResponse;
    }
}
